API Documentation
Public Member Functions | List of all members
nkMemory::String Class Referencefinal

Class holding information about a string, with ownership over the data. More...

Public Member Functions

 String ()
 
 String (const char *data)
 
 String (unsigned long long size)
 
 String (const char *data, unsigned long long size)
 
 String (const StringView &view)
 
 String (const String &other)
 
 String (String &&other) noexcept
 
 ~String ()
 
char * getData () const
 
unsigned long long getSize () const
 
bool empty () const
 
char & front ()
 
char & back ()
 
void clear ()
 
void resize (unsigned long long size)
 
Stringoperator= (const char *data)
 
Stringoperator= (const StringView &other)
 
Stringoperator= (const String &other)
 
Stringoperator= (String &&other) noexcept
 
const char operator[] (unsigned long long index) const
 
char & operator[] (unsigned long long index)
 
void operator+= (char value)
 
void operator+= (const StringView &other)
 
String operator+ (char c) const
 
String operator+ (const char *other) const
 
String operator+ (const StringView &other)
 
bool operator== (const char *other) const
 
bool operator== (const StringView &other) const
 
bool operator!= (const char *other) const
 
bool operator!= (const StringView &other) const
 
 String (const std::string &str)
 
 String (const std::string_view &str)
 
 operator std::string () const
 
 operator std::string_view () const
 
 operator nkLog::String () const
 
 operator nkLog::StringView () const
 
StringViewoperator= (const std::string &data)
 
StringViewoperator= (const std::string_view &data)
 

Detailed Description

Class holding information about a string, with ownership over the data.

This class will abstract a chain of characters and offer some utility to help manipulating them. The aim of this class is not to replace std::string within a codebase, but rather to offer a safe data exchange class from an app to the dlls, and the other way around. This class being fully exported, it doesn't suffer from the caveats a template can have in such situations.

To help in this dialog between app and dlls, the class is thought to be as transparent as possible between const char*, std::string and other widespread way of representing strings. Typical usage would just be to use standard structures in your app and benefit from the automatic converions from one type to another.

The String class will copy over memory and keep it in its own safe allocation. If memory safety is required, use this class. However, this can be slower as memory needs to be allocated and shuffled around. Unless this is required, prefer to use the StringView variant.

Constructor & Destructor Documentation

◆ String() [1/9]

nkMemory::String::String ( )

Default constructor. Will default to a nullptr data and a size of 0.

◆ String() [2/9]

nkMemory::String::String ( const char *  data)

Const char* constructor. Provided memory location will be copied based on its length. Be sure provided data is null-terminated.

Parameters
dataThe pointer to the chain of characters to take over.

◆ String() [3/9]

nkMemory::String::String ( unsigned long long  size)

Pre-allocation constructor. Data will be allocated depending on the size requested, and set to 0.

Parameters
sizeThe size of the chain to create, in number of chars.

◆ String() [4/9]

nkMemory::String::String ( const char *  data,
unsigned long long  size 
)

Guided const char* constructor. Provided memory location will be copied based on the size given. Prefer this constructor over the const char* constructor if you know the size required.

Parameters
dataThe pointer to the chain of characters to take over.
sizeThe size of the chain provided, in number of chars.

◆ String() [5/9]

nkMemory::String::String ( const StringView view)

View constructor. Memory location pointed by view will be copied over.

Parameters
viewThe view to copy the memory from.

◆ String() [6/9]

nkMemory::String::String ( const String other)

Copy constructor.

Parameters
otherThe string to copy from.

◆ String() [7/9]

nkMemory::String::String ( String &&  other)
noexcept

Move constructor.

Parameters
otherThe string to move over.

◆ ~String()

nkMemory::String::~String ( )

Destructor.

◆ String() [8/9]

nkMemory::String::String ( const std::string &  str)

Standard string constructor. The string provided will be copied over.

Parameters
strThe string to copy.

◆ String() [9/9]

nkMemory::String::String ( const std::string_view &  str)

Standard string view constructor. The view provided will be copied over.

Parameters
strThe view to copy.

Member Function Documentation

◆ getData()

char* nkMemory::String::getData ( ) const
Returns
A pointer over the memory of the string.

◆ getSize()

unsigned long long nkMemory::String::getSize ( ) const
Returns
The size of the string, in number of chars.

◆ empty()

bool nkMemory::String::empty ( ) const
Returns
Whether the string is of size 0, aka empty (true) or not (false).

◆ front()

char& nkMemory::String::front ( )
Returns
The first char in the string.

◆ back()

char& nkMemory::String::back ( )
Returns
The last char in the string.

◆ clear()

void nkMemory::String::clear ( )

Clears the string and frees its memory, returning it to its default state.

◆ resize()

void nkMemory::String::resize ( unsigned long long  size)

Resizes the internal memory of the string. Existing chars will be kept, while newly introduced ones will be set to 0.

Parameters
sizeThe new size the string should take, in number of chars.

◆ operator=() [1/6]

String& nkMemory::String::operator= ( const char *  data)

Const char* assignment operator.

Parameters
dataThe pointer over the memory to copy.

◆ operator=() [2/6]

String& nkMemory::String::operator= ( const StringView other)

View assignment operator.

Parameters
otherThe view over memory to copy.

◆ operator=() [3/6]

String& nkMemory::String::operator= ( const String other)

String copy assignment operator.

Parameters
otherThe string to copy.

◆ operator=() [4/6]

String& nkMemory::String::operator= ( String &&  other)
noexcept

String move assignment operator.

Parameters
otherThe string to move over.

◆ operator[]() [1/2]

const char nkMemory::String::operator[] ( unsigned long long  index) const

Const access operator.

Parameters
indexThe index of the char to access.

◆ operator[]() [2/2]

char& nkMemory::String::operator[] ( unsigned long long  index)

Access operator.

Parameters
indexThe index of the char to access.

◆ operator+=() [1/2]

void nkMemory::String::operator+= ( char  value)

Char append operator.

Parameters
valueThe char to append to the string.

◆ operator+=() [2/2]

void nkMemory::String::operator+= ( const StringView other)

View append operator.

Parameters
otherThe view to append to the string.

◆ operator+() [1/3]

String nkMemory::String::operator+ ( char  c) const

Char concatenation operator.

Parameters
cThe char to concatenate.
Returns
The result of the concatenation of calling string with the char provided.

◆ operator+() [2/3]

String nkMemory::String::operator+ ( const char *  other) const

Char chain concatenation operator.

Parameters
otherThe chain to concatenate with.
Returns
The result of the concatenation of calling string with the chain provided.

◆ operator+() [3/3]

String nkMemory::String::operator+ ( const StringView other)

View concatenation operator.

Parameters
otherThe view to concatenate with.
Returns
The result of the concatenation of calling string with the view provided.

◆ operator==() [1/2]

bool nkMemory::String::operator== ( const char *  other) const

Const char* equality operator.

Parameters
otherThe const char* to check equality with.
Returns
True if chains are the same, false otherwise.

◆ operator==() [2/2]

bool nkMemory::String::operator== ( const StringView other) const

View equality operator.

Parameters
otherThe view to check equality with.
Returns
True if chains are the same, false otherwise.

◆ operator!=() [1/2]

bool nkMemory::String::operator!= ( const char *  other) const

Const char* inequality operator.

Parameters
otherThe const char* to check equality with.
Returns
True if chains are difference, false otherwise.

◆ operator!=() [2/2]

bool nkMemory::String::operator!= ( const StringView other) const

View inequality operator.

Parameters
otherThe view to check equality with.
Returns
True if chains are difference, false otherwise.

◆ operator std::string()

nkMemory::String::operator std::string ( ) const

Conversion operator, to std::string.

◆ operator std::string_view()

nkMemory::String::operator std::string_view ( ) const

Conversion operator, to std::string_view.

◆ operator nkLog::String()

nkMemory::String::operator nkLog::String ( ) const

Conversion operator, to nkLog::String.

◆ operator nkLog::StringView()

nkMemory::String::operator nkLog::StringView ( ) const

Conversion operator, to nkLog::StringView.

◆ operator=() [5/6]

StringView& nkMemory::String::operator= ( const std::string &  data)

Templated assignment operator.

Parameters
dataThe string to assign.
Returns
A reference over calling string, once updated.

◆ operator=() [6/6]

StringView& nkMemory::String::operator= ( const std::string_view &  data)

Templated assignment operator.

Parameters
dataThe string view to assign.
Returns
A reference over calling string, once updated.

The documentation for this class was generated from the following file: